﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>
    
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">淘汰日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="date" id="eliminationDate" class="layui-input">
                    </div>



                    <button type="button" class="layui-btn layui-bg-red" onclick="Add()">新增</button>

                </div>


            </div>


            <table class="layui-table">
                <thead>
                    <tr>
                        <td>耳号</td>
                        <td>品种</td>
                        <td>当前栋舍</td>
                        <td>当前栏位</td>
                        <td>离场状态</td>
                        <td>淘汰原因</td>
                        <td>处理措施</td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <select id="earBugles">
                                <option value="">请选择</option>
                            </select>
                        </td>
                        <td>
                            <input type="text" id="variety" class="layui-input">
                        </td>
                        <td> <input type="text" id="eliminationHouse" class="layui-input"></td>
                        <td> <input type="text" id="eliminationField" class="layui-input"></td>
                        <td>

                            <select id="isDel">
                                <option value="">请选择</option>
                                <option value="true">已离场</option>
                                <option value="false">在场</option>
                            </select>

                        </td>
                        <td>
                            <select id="eliminationReasons">
                                <option value="">请选择淘汰原因</option>
                                <option value="空胎">空胎</option>
                                <option value="其他">其他</option>
                                <option value="老龄">老龄</option>
                                <option value="屡配不孕">屡配不孕</option>
                                <option value="习惯性流产">习惯性流产</option>
                                <option value="子宫脱">子宫脱</option>
                                <option value="子宫炎">子宫炎</option>
                                <option value="肥胖">肥胖</option>
                                <option value="消瘦">消瘦</option>
                                <option value="精液质量差">精液质量差</option>
                                <option value="拒配">拒配</option>
                                <option value="无乳">无乳</option>
                            </select>
                        </td>
                        <td>

                            <select id="treatmentMeasures">
                                <option value="">请选择</option>
                                <option value="销售">销售</option>
                                <option value="屠宰">屠宰</option>
                                <option value="无害化处理">无害化处理</option>
                            </select>

                        </td>
                    </tr>
                </tbody>
            </table>


            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" id=""></textarea>
                </div>
            </div>
        </div>

    </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>



</body>

</html>

<script>
    var form = layui.form;
    var $ = layui.jquery;

    $(function () {
        bangsheng();
    })
    function bangsheng() {

        $.ajax({
            url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
            data: JSON.stringify({}),
            type: "post",
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                console.log(res)
                $.each(res.data, function () {
                    $("#earBugles").append(`<option value="${this.recordId}">${this.recordAuricle}</option>`);
                })
                form.render('select'); // 重新渲染下拉框

            }

        })
    }

    function Add() {
        var data = {
            eliminationDate: null,
            sheepNumber: $("#earBugles").val(),
            variety: $("#variety").val(),
            eliminationHouse: $("eliminationHouse").val(),
            eliminationField: $("#eliminationField").val(),
            isDel: null,
            eliminationReasons: $("#eliminationReasons").val(),
            treatmentMeasures: $("#treatmentMeasures").val(),

        }
        console.log(data)

        $.ajax({
            url: "http://localhost:5269/api/SheepArchive/SheepCullingCreate",
            type: 'post',
            data: JSON.stringify(data),
            dataType: "json",
            contentType: "application/json",
            success: res => {
                if (res.code == 0) {
                    layer.msg('添加成功')
                }
                else {
                    layer.msg('保存失败')
                }
            }
        })
    }
</script>